<?php
namespace App\Services;

use Cache;

class Wechat
{
	
    public static function getUser()
    {
        $app = app('wechat.official_account');
        $users = $app->user->list();
        $arr = [];
       // dd($users);
        if($users['total']>10){
            $arr = array_chunk($users['data']['openid'], 10);
        } else {
            $arr = $users['data']['openid'];
        }

        $user_arr = [];    
        foreach ($arr as $key => $value) {
            $users = $app->user->select($value);
            $user_arr = array_merge($user_arr, $users['user_info_list']);

        }        
        return $user_arr;
    }

    public static function getUserInfo($openid)
    {
        $app = app('wechat.official_account');
        $userInfo = $app->user->get($openid);
        $data['nickname'] = $userInfo['nickname'];
        $data['headimgurl'] = $userInfo['headimgurl'];
        return $data;
    } 

    
    public static  function  refreshMenu(){
        $app = app('wechat.official_account.default');
        $menus = [
            [
                "type" => "view",
                "name" => "我的位置",
                "url"  => url('/index')
                ],
        ];
        return $app->menu->create($menus);
    }

}
?>